package yf.mall.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmojiFilter {
    public static void main(String[] args) {
        String input = "¹⁰红爆爆²⁰";
        String filtered = filterAll(input);
        System.out.println(filtered.length());
        System.out.println(filtered.substring(0,5));
    }

    public static String filterAll(String input) {
        // 使用正则表达式匹配只包含数字、汉字和字母的字符
        Pattern pattern = Pattern.compile("[^0-9a-zA-Z\\u4e00-\\u9fa5]");
        Matcher matcher = pattern.matcher(input);

        // 用空字符串替换匹配到的字符
        String filteredString = matcher.replaceAll("");

        return filteredString;
    }

    public static String removeEmojis(String text) {
        String regex = "[\\x{1F600}-\\x{1F64F}\\x{1F300}-\\x{1F5FF}\\x{1F680}-\\x{1F6FF}\\x{1F700}-\\x{1F77F}\\x{1F780}-\\x{1F7FF}\\x{1F800}-\\x{1F8FF}\\x{1F900}-\\x{1F9FF}\\x{1FA00}-\\x{1FA6F}\\x{1FA70}-\\x{1FAFF}\\x{1F000}-\\x{1F0CF}\\x{1F004}-\\x{1F0CF}\\x{1F170}-\\x{1F251}\\x{1F004}-\\x{1F251}\\x{1F004}-\\x{1F251}\\x{1F300}-\\x{1F5FF}\\x{1F600}-\\x{1F64F}\\x{1F680}-\\x{1F6FF}\\x{1F700}-\\x{1F77F}\\x{1F780}-\\x{1F7FF}\\x{1F800}-\\x{1F8FF}\\x{1F900}-\\x{1F9FF}\\x{1FA00}-\\x{1FA6F}\\x{1FA70}-\\x{1FAFF}\\x{1F000}-\\x{1F0CF}\\x{1F004}-\\x{1F0CF}\\x{1F170}-\\x{1F251}\\x{1F004}-\\x{1F251}]";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(text);
        return matcher.replaceAll("");
    }
}
